package cc.admin.common.db.table.entity;

import cn.hutool.core.collection.CollUtil;
import com.google.common.collect.Lists;
import lombok.Data;

import java.util.List;

/**
 * @Description: 元数据实体
 * @Author: ZhangHouYing
 * @date: 2018-06-24
 * @Version: V1.0.0
 */
@Data
public class DbEntity {

	/**
	 * 表名
	 */
	private String id;
	/**
	 * 中文名
	 */
	private String name;

	public DbEntity() {
		this.id = id;
		this.name = name;
	}

	public DbEntity(String id, String name) {
		this.id = id;
		this.name = name;
	}
	/**
	 * 字段列表
	 */
	List<DbColumn> dbColumnList;

	public List<DbColumn> getPkList(){
		List<DbColumn> pkList = Lists.newArrayList();
		if (CollUtil.isNotEmpty(dbColumnList)) {
			dbColumnList.forEach(dbColumn -> {
				if ("Y".equals(dbColumn.getIsKey())) {
					pkList.add(dbColumn);
				}
			});
		}
		return pkList;
	}
}
